
	;;; Description: Universal OUT of value. Uses OUT for normal ports and STS for memory_mapped ports.
	;;; Usage:       UOUT <address>, <value>
	;;; Example:     UOUT UDR,0xFF
	.macro OUTI          	
		LDI R16,@1
		.if @0 < 0x40
			OUT @0,R16       
		.else
			STS @0,R16
		.endif
	.endm

	;;; Description: Universal OUT. Uses OUT for normal ports and STS for memory_mapped ports.
	;;; Usage:       UOUT <addr>,<Rn>
	;;; Example:     UOUT UDR,R18
	.macro    UOUT        
		.if	@0 < 0x40
			OUT	@0,@1         
		.else
			STS	@0,@1
		.endif
	.endm
	
	;;; Description: Universal SET BIT with use of stack.
	;;;              Uses SBI for I/O registers below 0x20 or OUT for normal ports or STS for memory_mapped ports.
	;;; Usage:       SETBM <address>,<bitNo>
	;;; Example:     SETBM UDR,5
	.MACRO	SETBM 
		.if @0 < 0x20
			SBI	@0,@1
		.else
			.if @0<0x40
				PUSH	R17
				IN	R17,@0
				ORI	R17,1<<@1
				OUT	@0,R17
				POP	R17
			.else
				PUSH	R17
				LDS	R17,@0
				ORI	R17,1<<@1
				STS	@0,R17
				POP	R17
			.endif
		.endif
	.ENDM
 
	;;; Description: Universal SET BIT with use of temporary register.
	;;;              Uses SBI for I/O registers below 0x20 or OUT for normal ports or STS for memory_mapped ports.
	;;; Usage:       SETBM <address>,<bitNo>,<Rn_tmp>
	;;; Example:     SETBM UDR,5,R16
	.MACRO	SETB
		.if @0 < 0x20		; Low IO
			SBI	@0,@1
		.else
			.if @0<0x40		; High IO
				IN	@2,@0
				ORI	@2,1<<@1
				OUT	@0,@2
			.else			; Memory
				LDS	@2,@0
				ORI	@2,1<<@1
				STS	@0,@2
			.endif
		.endif
	.ENDM
;.............................................................
;Clear BIT with REG
	.MACRO	CLRB
	.if @0 < 0x20			; Low IO
	CBI	@0,@1
	.else
		.if @0<0x40		; High IO
	IN	@2,@0
	ANDI	@2,~(1<<@1)
	OUT	@0,@2
		.else			; Memory
	LDS	@2,@0
	ANDI	@2,~(1<<@1)
	STS	@0,@2
		.endif
	.endif
	.ENDM
 
;Clear BIT with STACK
	.MACRO	CLRBM 
	.if @0 < 0x20
	CBI	@0,@1
	.else
		.if @0<0x40
	PUSH	R17
	IN	R17,@0
	ANDI	R17,~(1<<@1)
	OUT	@0,R17
	POP	R17
		.else
	PUSH	R17
	LDS	R17,@0
	ANDI	R17,~(1<<@1)
	STS	@0,R17
	POP	R17
		.endif
	.endif
	.ENDM
;.............................................................
 
	.MACRO	INVB
	.if	@0 < 0x40
	IN	@2,@0
	LDI	@3,1<<@1
	EOR	@3,@2
	OUT	@0,@3
	.else
	LDS	@2,@0
	LDI	@3,1<<@1
	EOR	@2,@3
	STS	@0,@2
	.endif
	.ENDM
 
	.MACRO	INVBM
	.if	@0 < 0x40
	PUSH	R16
	PUSH	R17
	IN	R16,@0
	LDI	R17,1<<@1
	EOR	R17,R16
	OUT	@0,R17
	POP	R17
	POP	R16
	.else
	PUSH	R16
	PUSH	R17
	LDS	R16,@0
	LDI	R17,1<<@1
	EOR	R17,R16
	STS	@0,R17
	POP	R17
	POP	R16
	.endif
	.ENDM